//
//  AXMyZyxnrVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/7.
//  Copyright © 2018 tzhg. All rights reserved.
//
/** 职业新农人 */
 
#import "AXMyZyxnrVC.h"
#import "ZXCategories.h"
#import "UIView+SDAutoLayout.h"
#import "AXMyNewFarmerNameCell.h"
#import "AXMyNewFarmerSexCell.h"
#import "AXMyNewFarmerPictureCell.h"
#import "AXMyNewFarmerSubmitCell.h"
#import "TZHGMyViewController.h"


@interface AXMyZyxnrVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;

@end

@implementation AXMyZyxnrVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    
}


- (void)creatView {
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    /** tableView滚动收键盘 */
     self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXMyNewFarmerNameCell class] forCellReuseIdentifier:[AXMyNewFarmerNameCell reuseID]];
    [self.tableView registerClass:[AXMyNewFarmerSexCell class] forCellReuseIdentifier:[AXMyNewFarmerSexCell reuseID]];
    [self.tableView registerClass:[AXMyNewFarmerPictureCell class] forCellReuseIdentifier:[AXMyNewFarmerPictureCell reuseID]];
    [self.tableView registerClass:[AXMyNewFarmerSubmitCell class] forCellReuseIdentifier:[AXMyNewFarmerSubmitCell reuseID]];
    [self.view addSubview:self.tableView];
}


- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, NAVIGATION_HEIGHT)
    .widthIs(Wi)
    .heightIs(TableViewHeight);
    
    
}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    /** 搜索 */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"职业新农人";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark - tableviewDlegate & tableviewDelegate

//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 14;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 4) {
        
        return 200;
    }else if (indexPath.row == 9){
        
        
        return 150;
    }
    
    
    return 44;
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
  
    /** 姓名 */
    if (indexPath.row == 0||indexPath.row ==2||indexPath.row ==3||indexPath.row ==5||indexPath.row ==6||indexPath.row==7) {
        
        AXMyNewFarmerNameCell *nameCell = [tableView dequeueReusableCellWithIdentifier:[AXMyNewFarmerNameCell reuseID] forIndexPath:indexPath];
        [nameCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        if (indexPath.row == 0) {
            
            nameCell.nameLabel.text = @"姓名";
            
        }else if (indexPath.row == 2) {
            
             nameCell.nameLabel.text = @"手机号";
            
        }else if (indexPath.row == 3) {
            
            nameCell.nameLabel.text = @"身份证号";
        }
        else if (indexPath.row == 5) {
            
            nameCell.nameLabel.text = @"家庭住址";
        }
        
        else if (indexPath.row == 6) {
            
            nameCell.nameLabel.text = @"详细地址";
        }
        else if (indexPath.row == 7) {
            
            nameCell.nameLabel.text = @"劳动人数";
        }
        

        
        return nameCell;
    }
    
    if (indexPath.row == 4||indexPath.row == 9) {
        
        AXMyNewFarmerPictureCell *pictureCell = [tableView dequeueReusableCellWithIdentifier:[AXMyNewFarmerPictureCell reuseID] forIndexPath:indexPath];
        [pictureCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        if (indexPath.row == 4) {
            
            pictureCell.sfzLabel.text= @"身份证照片";
            pictureCell.frontLabel.text = @"正面";
            pictureCell.reverseSideLabel.text = @"反面";
        }
        else if (indexPath.row == 9) {
            
             pictureCell.sfzLabel.text= @"上传证明";
            pictureCell.reverseSideBtn.hidden = YES;
        }
      
        
        
        return  pictureCell;
       
    }
    
    
    if (indexPath.row == 13) {
        
        AXMyNewFarmerSubmitCell *submitCell = [tableView dequeueReusableCellWithIdentifier:[ AXMyNewFarmerSubmitCell reuseID] forIndexPath:indexPath];
        [submitCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [submitCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        submitCell.saveBtn.hidden = YES;
        submitCell.saveBtn.cornerRadius =5;
        submitCell.SelectBtn.hidden = NO;
        submitCell.agreeLabel.hidden = NO;
        submitCell.submiBtn.hidden = NO;
        submitCell.agreeLabel.text = @"同意入驻协议";
        [submitCell.submiBtn setTitle:@"确认提交" forState:UIControlStateNormal];
        submitCell.tapButtonClickedBlock = ^(NSInteger index) {
            
            //做一个全局存储 用于判断是否入驻
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"EnterAgriculture"];
            //发送通知
            NSNotification *notification = [NSNotification notificationWithName:@"EnterAgriculture" object:nil userInfo:nil];
            [[NSNotificationCenter defaultCenter] postNotification:notification];
            [self.navigationController popToRootViewControllerAnimated:YES];
            
        };
        

        return submitCell;
        
    }
    
    
    
    
    AXMyNewFarmerSexCell *farmerSexCell = [tableView dequeueReusableCellWithIdentifier:[AXMyNewFarmerSexCell reuseID] forIndexPath:indexPath];
    [farmerSexCell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    if (indexPath.row == 1) {
        
        farmerSexCell.sexLabel.text = @"性别";
        farmerSexCell.womanLabel.text = @"女";
        farmerSexCell.manLabel.text = @"男";
    }
    else if (indexPath.row == 8) {
        
      farmerSexCell.sexLabel.text = @"是否贫困户";
        farmerSexCell.womanLabel.text = @"否";
        farmerSexCell.manLabel.text = @"是";
        
    }else if (indexPath.row == 10) {
        
        farmerSexCell.sexLabel.text = @"是否技术托管";
    }else if (indexPath.row == 11) {
        
        farmerSexCell.sexLabel.text = @"是否委托销售";
    }
    else if (indexPath.row == 12) {
        
        farmerSexCell.sexLabel.text = @"是否委托采购农资";
    }
  
    
    return farmerSexCell;
    
    
}




@end
